1848F - Vika and Wiki - CodeForces Solution


binary search bitmasks combinatorics dp math

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
// #define int long long
// #define ll long long int
int INF = 2e18;
int n;
int check(vector<int> v, int k){
    for (int b=19; b>=0; b--) if ((k>>b)&1) {
        int bp = (1<<b);
        vector<int> w = v;
        for (int i=0; i<n; i++) w[i] = v[i]^v[(i+bp)%n];
        v = w;
    }
    vector<int> Z(n, 0);
    return v == Z;
}
void solve(){
    cin >> n;
    vector<int> v(n);
    vector<int> Z(n, 0);
    for (int i=0; i<n; i++) cin >> v[i];
    if (v==Z){
        cout << "0\n";return;
    }
    int low = 0; int high = n;
    // cout << check(v, 2ll) << "\n";
    while (high-low>1){
        int mid = (low+high)/2;
        if (check(v, mid)) high = mid;
        else low = mid;
    }
    cout << high << "\n";
}
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
	// inv_init(1e6);
    int t; t=1;
    // cin >> t;
    for (int i=0; i<t; i++) solve();
}   


Comments

Submit
0 Comments
More Questions

Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array